package TestDemo;

class Counter {
    public int count;
    public void increase() {
        synchronized(this) {
            count++;
        }
    }
}

public class TestDemo1 {
    public static int count = 0;

    public static void main(String[] args) {
        Counter counter = new Counter();
    }

    public static synchronized void increase() {
        count++;
    }
    public static void main1(String[] args) {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5_0000; i++) {
                increase();
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 5_0000; i++) {
                increase();
            }
        });
        t1.start();
        t2.start();

        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(count);
    }
}
